package com.nbx.app.zeuscmdport;


import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.graphics.Bitmap;
import android.opengl.GLU;
import android.opengl.GLUtils;
import android.view.MotionEvent;

/**
 * http://www.zeuscmd.com/tutorials/opengles/10-Transformations.php
 * 
 * @author 5109200610
 *
 */
public class Render19 extends RenderBase {

	private float rectangle[] = {
		-1.0f, -0.25f,
		 1.0f, -0.25f,
		-1.0f,  0.25f,
		 1.0f,  0.25f
	};

	int currBlend = 4;

	private int blendSrc[] = {
			GL10.GL_ONE,
			GL10.GL_ONE,
			GL10.GL_ONE,
			GL10.GL_SRC_ALPHA,
			GL10.GL_SRC_ALPHA
	};

	private int blendDst[] = {
			GL10.GL_ZERO,
			GL10.GL_ONE,
			GL10.GL_ONE_MINUS_DST_ALPHA,
			GL10.GL_ONE,
			GL10.GL_ONE_MINUS_SRC_ALPHA
	};

	private FloatBuffer mBoxBuffer;

	
	public Render19(Context context) {
		super(context);
	}

	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		mBoxBuffer = createFloatBuffer(rectangle); 

		gl.glClearColor (0.25f, 0.25f, 0.25f, 1.0f);

		gl.glEnable(GL10.GL_BLEND);
		gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
	}

	public void onSurfaceChanged(GL10 gl, int width, int height) {
		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glLoadIdentity();

		gl.glViewport(0, 0, width, height);
		gl.glOrthof(0.0f, 3.0f, 0.0f, 3.0f, -1.0f, 1.0f);
		//GLU.gluPerspective(gl, 45.0f, 1.0f * width / height, 1.0f, 100.0f);

		gl.glMatrixMode(GL10.GL_MODELVIEW);
		gl.glLoadIdentity();
	}

	public void onDrawFrame(GL10 gl) {
		gl.glClear (GL10.GL_COLOR_BUFFER_BIT);
		gl.glLoadIdentity();

		gl.glVertexPointer(2, GL10.GL_FLOAT, 0, mBoxBuffer);

		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

		gl.glPushMatrix();
			gl.glTranslatef(1.5f, 2.0f, 0.0f);
			gl.glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
		gl.glPopMatrix();

		gl.glPushMatrix();
			gl.glTranslatef(0.7f, 1.5f, 0.0f);
			gl.glRotatef(90.0f, 0.0f ,0.0f, 1.0f);
			gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
		gl.glPopMatrix();

		gl.glPushMatrix();
			gl.glTranslatef(1.7f, 1.5f, 0.0f);
			gl.glRotatef(90.0f, 0.0f ,0.0f, 1.0f);
			gl.glColor4f(0.0f, 0.0f, 1.0f, 0.25f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
		gl.glPopMatrix();

		gl.glPushMatrix();
			gl.glTranslatef(1.5f, 1.0f, 0.0f);
			gl.glColor4f(1.0f, 1.0f, 0.0f, 0.75f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
		gl.glPopMatrix();
	}
	

	@Override
	public boolean handleTouchEvent(MotionEvent event) {

		return true;
	}
}